package approval.dao;

import java.sql.PreparedStatement;
import java.sql.ResultSet;

import model.pojo.ListApprove;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;

import models.util.MySqlDataAccessHelper;

public class myapproveDAO {

	MySqlDataAccessHelper hep=new MySqlDataAccessHelper();
	PreparedStatement pr=null;
	DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	ArrayList<ListApprove> loadAllApprover=null;
	
	public ArrayList<ListApprove> getLoadAllApprover(String databasename,String idgruopapp,String lang) {
		loadAllApprover=new ArrayList<ListApprove>();
		try{
			hep.open(databasename);
				String sql="";
			sql+="select l.ID,l.IDGroupApprove,l.IDEmployee,l.IDtypeApprove,l.Order,l.IDStatus,l.DateApprove,l.Description,e.FullName";
					if(lang.equals("VN")) 
						sql+=",st.VN ";
					else if(lang.equals("EN")) 
						sql+=",st.EN ";
					else if(lang.equals("KR")) 
						sql+=",st.KR ";
					sql+=" from listapprove as l,employee as e,status as s,staticlang as st " +
							"where l.IDEmployee=e.IDEmployee and st.IDConfigStaticLang=s.IDConfigStaticLang and l.IDGroupApprove='"+idgruopapp+"' and s.IDStatus=l.IDStatus" ;
			ResultSet rs=hep.executeQuery(sql);
			while(rs.next()){
				ListApprove la=new ListApprove(rs.getInt("ID"), rs.getString("IDGroupApprove"), rs.getString("IDEmployee"), rs.getInt("IDtypeApprove"),
						rs.getInt("Order"), rs.getInt("IDStatus"), rs.getString("DateApprove"), rs.getString("Description"));
				la.setFullnameEmp(rs.getString("FullName"));
				if(lang.equals("VN")) 
					la.setStatus_(rs.getString("VN"));
				else if(lang.equals("EN")) 
					la.setStatus_(rs.getString("EN"));
				else if(lang.equals("KR")) 
					la.setStatus_(rs.getString("KR"));
				loadAllApprover.add(la);
			}
		}
		catch (Exception e) {
			e.printStackTrace();
		}
		finally{
			hep.close();
		}
		return loadAllApprover;
	}
	
}
